<template>
    <el-dialog title="定价单详情" :visible.sync="FixPriceDetailsDialog" @close="handleClose()" width="60rem" class="dialog">
        <template slot="title">
            <span
                style="color: rgba(52, 69, 99, 1); font-size: 18px;font-weight: bold; margin-left: 5px;margin-top: 34px;">定价单详情</span>
            <br /><br />
            <hr />
        </template>
        <div class="dialog-content">
            <el-form ref="form" :model="showForm">
                <el-form-item label="定价商品" label-width="90px"/>
                <div class="productTable">
                    <el-tag>
                        {{ commodityName }}
                    </el-tag>
                    <el-table :data="[showForm]" border>
                        <el-table-column v-for="(item,index) in tableColumns" :key="index" :label="item.key" :prop="item.value"
                            min-width="100">
                            {{ item.value }}
                        </el-table-column>
                        <el-table-column prop="priceType" label="定价类型" width="129" :resizable="false">
                            {{ showForm.fixPriceType == 1 ? '固定价格' : '面议'  }}
                        </el-table-column>
                        <el-table-column prop="price" label="零售价" width="129" :resizable="false">
                            <div  v-if="showForm.fixPriceType == 1">￥{{ showForm.fixPrice  }}</div>
                        </el-table-column>
                        <el-table-column prop="priceUnit" label="价格单位" width="129"
                            :resizable="false">
                            <div  v-if="showForm.fixPriceType == 1">
                                {{ showForm.priceUnit == 1 ? '元' : showForm.priceUnit == 2 ? '千元' : '万元' }}
                            </div>
                        </el-table-column>
                        <el-table-column prop="inventoryProcessing" label="库存处理" width="129"
                            :resizable="false">
                            {{ showForm.stockType == 1 ? '自动出库' : '不记库存'  }}
                        </el-table-column>
                    </el-table>
                </div>
            </el-form>
        </div>
    </el-dialog>
</template>

<script>
import { getPriceDetail } from '@/api/api.js'
export default {
    props: {
        dialogVisible: {
            type: Boolean,
            default: false
        },
        rowData: {
            type: Object,
            default: () =>({})
        }
    },
    data() {
        return {
            FixPriceDetailsDialog: this.dialogVisible,
            showForm:{},
            tableColumns:[],
            commodityName:'',
        }
    },
    methods: {
        handleClose() {
            this.$emit('update:dialogVisible', false); // 发送事件以更新父组件的 prop
            // this.showForm = {}
            // this.tableColumns = []
        },
    },
    watch: {
        dialogVisible(newVal) {
            this.FixPriceDetailsDialog = newVal;
        },
        async rowData(newVal){
            this.commodityName = newVal.commodityName
            const res = await getPriceDetail(newVal.batchNumber,newVal.commodityId)
            console.log(newVal.skuCode)
            const r = res.data.result.filter(el=>{
                return el.skuCode == newVal.skuCode
            })
            this.showForm = r[0]
            this.tableColumns = JSON.parse(r[0].spData)
            console.log(this.tableColumns)
        }
    }
}
</script>

<style scoped>
.dialog {
    max-height: 100vh !important;
    overflow-y: hidden;
    left: 15%;
}

.dialog-content {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    height: 480px;
}

.el-icon-search {
    margin-top: 14px;
    width: 15px;
    margin-left: 6px;
}

.el-pagination {
    float: right;
}

.dialog-footer {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 100%;
    display: flex;
    justify-content: flex-end;
    background-color: #fff;
    padding: 10px 20px;
    border-top: 1px solid #ebeef5;
}

.footer-button {
    font-size: 14px;
    height: 38px;
    width: 150px;
    margin-right: 8px;
}

.confirm-button {
    background-color: rgba(90, 52, 179, 1);
    color: white;
}
</style>
